<?php   // $Id: fact_multi_facture.php 275 2008-08-12 20:41:04Z pcoustillas $ ?>
<?php   
/*Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx
Modification : Pierre Coustillas*/

require_once("include/verif.php");
require_once("include/config/common.php");
require_once("include/config/var.php");
require_once("include/language/$lang.php");
require_once("include/utils.php");
require_once("include/headers.php");


?>


<table class="page" align="center">
	<tr>
		<td class="page" align="center">
		<?php
		require_once("include/head.php");
		?>
		</td>
	</tr>
	<tr>
		<td class="page" align="center">
			<center>
			<?php
			if ($user_fact == "n") { 
				echo "<h1>$lang_facture_droit</h1>";
				exit;
			}
 


			$sql_fact = "SELECT date_fact FROM ${tblpref}facture ORDER BY date_fact DESC LIMIT 1";
			$result = mysql_query($sql_fact) or die("Erreur SQL !<br/>$sql_fact<br/>" . mysql_error());
			$date_derniere_fact = mysql_result($result,0);
			$date_derniere_fact = sql_to_date($date_derniere_fact); //ne pas déplacer après l'appel à javascript
			
			$mois = date("m");
			$annee = date("Y");
			$jour = date("d");
			$rqSql = "SELECT num_client, nom FROM ${tblpref}client WHERE actif != 'non' ORDER BY nom";

			$result = mysql_query( $rqSql ) or die( "Erreur selection client.<br/>$rqSql");
			
			?>
			
			<script language="javascript" src="javascripts/verifier_form.js" type="text/javascript"></script>
			<script type="text/javascript">
				function verif_creer_fact()
				{
					if (verifier('form_facture','black','date_deb','vide#date_','date_fin','vide#date_','date_fact','vide#date_#est_inf_a_date%<?php echo $date_derniere_fact ?>','acompte','est_nombre'))
					{
						document.form_facture.submit();
					} else {
						alert("<?php aff_lang('Une des valeurs saisie n\'est pas correct.\nMerci de corriger avant de poursuivre.') ?>")
					}
			
				}
			</script>

			<form name="form_facture" method="post" action="fact_multi_facture_suite.php">
			<table class="boiteaction">
				<caption><?php echo $lang_facture_creer; ?> &nbsp;  &nbsp;  &nbsp; <?php bouton_aide("fact_creer_multiple") ?></caption>
				<tr> 
					<td class="texte0"> <?php echo $lang_client; ?> </td>
					<td class="texte0" >
						<select multiple="multiple" name='client[]' size="10">
							<?php
								while ( $row = mysql_fetch_array( $result)) {
									$numclient = $row["num_client"];
									$nom = $row["nom"];
									?>
								<option value='<?php echo $row["num_client"]; ?>'><?php echo $row["nom"]; ?></option>
								<?php
								}
								?>
						</select>
					</td>
				</tr>
				<tr>
					<td class='<?php echo couleur_alternee (); ?>' id="date_deb"><?php aff_lang("Bon de commande à partir du ") ?></td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input type="text" name="date_deb" value="<?php echo "01/$mois/$annee" ?>" />
							<a href="#" onclick="window.open('include/pop.calendrier.php?frm=form_facture&amp;ch=date_deb','calendrier','width=415,height=190,left=200,top=200,scrollbars=0').focus();"><img src="image/petit_calendrier.gif" alt="calendrier" border="0"/></a>
					</td>
				</tr>
				<tr>
					<td class='<?php echo couleur_alternee (); ?>' id="date_fin"><?php aff_lang("Bon de commande jusqu'au ") ?></td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input type="text" name="date_fin" value="<?php echo "$jour/$mois/$annee" ?>" />
						<a href="#" onclick="window.open('include/pop.calendrier.php?frm=form_facture&amp;ch=date_fin','calendrier','width=415,height=190,left=200,top=200,scrollbars=0').focus();"><img src="image/petit_calendrier.gif" alt="calendrier" border="0"/></a>
					</td>
				</tr>
				<tr>
					<td class='<?php echo couleur_alternee (); ?>' id="date_fact">
						<?php echo $lang_facture_date; ?> (<?php echo get_lang("date de la dernière facture") . " : " . $date_derniere_fact . ")" ?>
					</td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input type="text" name="date_fact" value="<?php echo "$jour/$mois/$annee" ?>" />
						<a href="#" onclick="window.open('include/pop.calendrier.php?frm=form_facture&amp;ch=date_fact','calendrier','width=415,height=190,left=200,top=200,scrollbars=0').focus();"><img src="image/petit_calendrier.gif" alt="calendier" border="0"/></a>
					</td>
				</tr>
				<tr>
					<td class='<?php echo couleur_alternee (); ?>' id="acompte"><?php aff_lang("Acompte pour toutes les factures") ?></td>
					<td class='<?php echo couleur_alternee (FALSE); ?>'>
						<input type="text" name="acompte" value="" size="10" /> <?php echo$devise; ?>
					</td>
				</tr>
				<tr>
					<td class="submit" colspan="2" ><br/><?php echo $lang_ajo_fact ?></td>
				</tr>
				<tr>
					<td class="submit" colspan="2">
						<textarea name="coment" cols="45" rows="3"></textarea>
					</td>
				</tr>
				<tr>
					<td class="submit" colspan="2">
						<input type="button" onclick="verif_creer_fact()" value="     <?php aff_lang("Créer la/les facture(s)") ?>     " />
					</td>
				</tr>
			</table>
			</form>
			</center>
		</td>
	</tr>
	<tr>
		<td>
			<?php
			require_once("include/bas.php");
			?>
		</td>
	</tr>

</table>
</body>
</html>
